package com.eb.buybuybuy.controller;

import com.eb.buybuybuy.annotation.*;
import com.eb.buybuybuy.constant.RequestMethodConstant;
import com.eb.buybuybuy.constant.RequestMethodEnum;
import com.eb.buybuybuy.core.IOC;
import com.eb.buybuybuy.result.Result;
import com.eb.buybuybuy.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Component
@HttpController("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @Entrance(path = "/list", method = RequestMethodEnum.GET)
    public Object list(@SessionParameter HttpSession session) throws Exception {
        return cartService.list(session);
    }

    @Entrance(path = "/increase", method = RequestMethodEnum.POST)
    public Object increase(@RequestParameter("goodsId") String goodsId, @SessionParameter HttpSession session) throws Exception {
        cartService.increase(session, Integer.valueOf(goodsId));
        return null;
    }

    @Entrance(path = "/decrease", method = RequestMethodEnum.POST)
    public Object decrease(@RequestParameter("goodsId") String goodsId, @SessionParameter HttpSession session) throws Exception {
        cartService.decrease(session, Integer.valueOf(goodsId));
        return null;
    }

    @Entrance(path = "/buy", method = RequestMethodEnum.POST)
    public Object buy(@SessionParameter HttpSession session) throws Exception {
        cartService.buy(session);
        return null;
    }
}
